package com.gjy.design.proxy.cglib;

import net.sf.cglib.proxy.Enhancer;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-11-10 10:53:51
 */
public class DemoCglib {

    @SuppressWarnings("unchecked")
    public static <T> T createCglibProxy(T target, Class<T> superClass) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(superClass);
        enhancer.setCallback(new CglibLoggingInterceptor(target));
        enhancer.setClassLoader(target.getClass().getClassLoader());
        return (T) enhancer.create();
    }

    public static void main(String[] args) {
        PaymentService real = new PaymentService();
        PaymentService proxy = createCglibProxy(real, PaymentService.class);
        proxy.pay("ORD-003", 99.99);
    }

}
